package com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.InviteBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ItemViewDelegate;
import com.hanhanxiaochong.zhongxiangchuanmei.config.MultiItemTypeAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.utils.TimeUtils;

import java.util.List;

/**
 * Created by rockphoenix on 2018/7/16.
 */

public class InviteSecondAdapter extends MultiItemTypeAdapter<InviteBean.ListBean> {

    public InviteSecondAdapter(Context context, List<InviteBean.ListBean> datas) {
        super(context, datas);
        addItemViewDelegate(new InviteHeaderDelegate());
        addItemViewDelegate(new InviteSecondDelegate());
    }

    class InviteHeaderDelegate implements ItemViewDelegate<InviteBean.ListBean> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_second_invite_header;
        }

        @Override
        public boolean isForViewType(InviteBean.ListBean item, int position) {
            return item.isUser();
        }

        @Override
        public void convert(ViewHolder holder, InviteBean.ListBean bean, int position) {
            ImageView avatar = holder.getView(R.id.iv_invite_avatar);
            GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getAvatar(), R.mipmap.img_error, R.mipmap.img_error, avatar);
            holder.setText(R.id.tv_invite_name, bean.getUser_nicename());
            holder.setText(R.id.tv_invite_id, "ID " + bean.getU_id());
            holder.setText(R.id.tv_phone_number, "联系电话：" + bean.getMobile());
            holder.setText(R.id.tv_register_time, "注册时间：" + TimeUtils.getDateFromSeconds(bean.getCreate_time()));
            // 2:会员;0:普通用户
            holder.setText(R.id.tv_invite_level, bean.getMember_name());
            holder.setText(R.id.tv_consume_times, "消费次数：" + bean.getShop() + "次");
        }
    }

    class InviteSecondDelegate implements ItemViewDelegate<InviteBean.ListBean> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_my_invite;
        }

        @Override
        public boolean isForViewType(InviteBean.ListBean item, int position) {
            return !item.isUser();
        }

        @Override
        public void convert(ViewHolder holder, InviteBean.ListBean bean, int position) {
            ImageView avatar = holder.getView(R.id.iv_invite_avatar);
            GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getAvatar(), R.mipmap.img_error, R.mipmap.img_error, avatar);
            holder.setText(R.id.tv_invite_name, bean.getUser_nicename());
            holder.setText(R.id.tv_invite_id, "ID " + bean.getU_id());
            holder.setText(R.id.tv_phone_number, "联系电话：" + bean.getMobile());
            holder.setText(R.id.tv_register_time, "注册时间：" + TimeUtils.getDateFromSeconds(bean.getCreate_time()));
            // 2:会员;0:普通用户
            holder.setText(R.id.tv_invite_level, bean.getMember_name());
            holder.setText(R.id.tv_consume_times, "消费次数：" + bean.getShop() + "次");
            holder.setText(R.id.tv_invite_benefit, "给我创造收益：" + bean.getPar() + "元");
        }
    }
}
